<!--
 * @Author: your name
 * @Date: 2020-09-02 12:00:20
 * @LastEditTime: 2020-09-03 16:46:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \admin-management\web\src\components\form-item\custom-switch.vue
-->
<template>
  <a-switch v-model:checked="checkValue" />
</template>

<script>
import { computed } from 'vue';
export default {
  name: 'CustomSwitch',
  props: {
    value: {
      type: Number,
      default: 0
    }
  },
  setup(props, { emit }) {
    let checkValue = computed({
      get() {
        return props.value === 0 ? false : true;
      },
      set(val) {
        let checked = val ? 1 : 0;
        emit('update:value', checked);
      }
    });
    return {
      checkValue
    };
  }
};
</script>
